home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)inputs.c V1.21 3/13/95";
- #endif
- /*
- | file name - inputs.c
- |===================================================================
- |
- | Example program that shows how to use views that contain
- | input objects.
- |
- | The view contains a menu and a slider. The slider
- | affects a graph that is found in the view. The variable
- | descriptors of the two objects have been pointed to the
- | same data source variable. Therefore, when the slider
- | is moved, the data source variable's buffer address is
- | modified to reflect the change which will be reflected
- | in the graph after it has been updated. The menu is an
- | action menu used to draw and erase a circle and a
- | rectangle object found in the view. The menu selection
- | determines which action is to be performed. A service
- | result request is posted on the input object to determine
- | when a selection has been made. The service result code
- | INPUT_DONE is generated for a menu selection. The
- | service result routine HandleInput is called once a
- | selection is made and the buffer address of the data
- | source variable is examined to determine the course of
- | action to be taken.
- |
- | Typing a <q> or <Q> will exit the program.
- |
- |===================================================================
- */
- #include<windows.h>
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "inputs.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define CLIENT (OBJECT)1
- #define DONE_LABEL (int)1
- #define DRAW_CIRCLE (int)1
- #define ERASE_CIRCLE (int)2
- #define DRAW_RECT (int)3
- #define ERASE_RECT (int)4
-
- /* Whole world rectangle, (-16384, -16384) to (16383, 16383)*/
- RECTANGLE whole_world = {XMIN, YMIN, XMAX, YMAX};
-
- /*
- * Information to be passed on to the service result
- * routine HandleInput().
- */
- typedef struct
- {
- DRAWPORT drawport; /* how & where to display picture, picture frame */
- OBJECT circle; /* circle object in view */
- OBJECT rectangle; /* rectangle object in view */
- float *data_ptr; /* buffer address of data source variable */
- } INFO;
-
- /* Functions defined in inputs.c */
- int main V_P_((int argc, char *argv[]));
- int HandleInput V_P_((OBJECT client, EVENT_REQUEST er, int label,
- OBJECT loc, ADDRESS args)); /* service result routine */
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
-
- /*
- * program arguments
- * argv[1] - display device (default is DVDEVICE)
- */
-
- /* Define & initialize device name and view filename */
- char *device_name = DVDEVICE; /* default device name */
- char *view_name = VIEW_NAME; /* default view name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
-
- /* Input object related variables */
- OBJECT drawing, /* graphical representation of screen */
- menu; /* text menu input object */
- ADDRESS *vdplist; /* variable descriptor list for menu */
- int numvars; /* number of vdps in list */
- DSVAR dsvar; /* data source variable bound to vdp */
- INFO info; /* struct passed to service result routine */
- int event_req_status; /* status of event requests */
-
- /* Other variables */
- int Quit = NO; /* flag to quit program */
-
- /*-----------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- TInit (DVPATH, DISPFORMS_STB);
-
- /*
- * TscOpenSet: opens a device as a screen object using
- * specified attributes
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS |
- V_EXPOSE | V_RESIZE | V_MOTIONNOTIFY,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view in from a file,
- * TdpCreateStretch: Create a drawport with stretched coordinates
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- * Objects of the view are stretched to make the
- * the portion of the view specified as whole_world
- * fit in the specified viewport, SCREEN_VIEWPORT.
- */
- view = TviLoad (view_name);
- if (!view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name);
- S_EXIT (EXIT_ERR);
- }
- info.drawport = TdpCreateStretch (screen, view,
- SCREEN_VIEWPORT, &whole_world);
-
- /*
- * TviGetDrawing: Gets a view's drawing object
- * TdrGetNamedObject: Gets a named object from a
- * drawing.
- *
- * Get the circle, rectangle and text menu input
- * objects from the view's drawing.
- */
- drawing = TviGetDrawing (view);
- info.circle = TdrGetNamedObject (drawing, "circle.obj");
- info.rectangle = TdrGetNamedObject (drawing, "rect.obj");
- menu = TdrGetNamedObject (drawing, "menu.input");
-
- /*
- * VOinGetVarList: Gets a variable descriptor list of
- * the input object.
- * TvdGetDataSourceVariable: Gets the data source variable
- * which the variable descriptor
- * (vdp) is linked to.
- * TdsvGetBuffer: Gets data source variable (dsv)
- * buffer address.
- *
- * Obtain the vdp list for the text menu input object.
- * Find the data source variable which the vdp is linked
- * to. Then obtain the buffer address which the data
- * source variable is pointing to.
- */
- VOinGetVarList (menu, &vdplist, &numvars);
- dsvar = TvdGetDataSourceVariable (vdplist[0]);
- info.data_ptr = (float *) TdsvGetBuffer (dsvar);
-
- /*
- * VUerServiceResultPost: Post a service result request
- * with the event handler.
- *
- * Post a service result request which monitors the
- * text menu input object. The request specifies the
- * type of the service result flag to be generated as
- * an INPUT_DONE. INPUT_DONE indicates an input sequence
- * has been completed (a menu selection was made).
- */
- VUerServiceResultPost (CLIENT, (VUERFCNFUNPTR)HandleInput,
- (ADDRESS) & info, (int)sizeof (info), menu,
- (int)INPUT_DONE, DONE_LABEL);
-
- /*
- * TscErase: Erase the entire screen in the default
- * background color
- * TdpDraw: Draw the contents of the drawport
- */
- TscErase (screen);
- TdpDraw (info.drawport);
-
- /*--------------------
- * Control loop
- *
- * Poll the event queue for window events. If the key
- * represents the character 'q' or 'Q' then quit the program.
- * Events occurring within input objects will be handled
- * through the event request handler VUerHandleLocEvent
- * and continually update the dynamic objects.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- * The polling mode used is V_NO_WAIT.
- * Using this mode, VOloWinEventPoll
- * does not wait until a masked event
- * is generated.
- *
- * VUerHandleLocEvent: Service the event. This routine will check
- * if the event is used by any input objects
- * that may be in the view.
- */
- location = VOloWinEventPoll (V_NO_WAIT);
- if (location)
- {
- event_req_status = VUerHandleLocEvent (location);
-
- /*
- * If the return value of VUerHandleLocEvent is INPUT_UNUSED
- * then check for keypress or buttonpress events which
- * represent one of the exit keys as well as resize
- * and expose events.
- */
- if (event_req_status == INPUT_UNUSED)
- {
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- */
- TscReset (screen);
- break;
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- *
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
-
- default:
- break;
- }
- break;
-
- case V_BUTTONPRESS:
- case V_MOTIONNOTIFY:
- default:
- break;
- }
- }
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
-
- /*
- * TdpDrawNext: Update all dynamic objects within a
- * drawport's view.
- * Update dynamics
- */
- TdpDrawNext (info.drawport);
- }
-
- /*--------------------
- * Termination
- *
- * VUerClearAll: Clears a client's event requests
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscCloseCurrentScreen: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- VUerClearAll (CLIENT);
- TdpDestroy (info.drawport);
- TviDestroy (view);
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-
-
- /*--------------
- * HandleInput -- Perform the appropriate action based
- * on the user's menu selection. A circle or
- * rectangle object is drawn or erased.
- */
- /*ARGSUSED*/
- int
- HandleInput (client, er, label, loc, args)
- OBJECT client;
- EVENT_REQUEST er;
- int label;
- OBJECT loc;
- ADDRESS args;
- {
-
- INFO *info = (INFO *)args;
- /*
- * TdpDrawObject: Draw a specific object within a drawport
- * TdpEraseObject: Erase an object within a drawport
- *
- * Examine the data source variable buffer address which
- * is updated by the input object when a selection has
- * been made.
- */
- switch ((int) (*info->data_ptr))
- {
- case DRAW_CIRCLE:
- TdpDrawObject (info->drawport, info->circle);
- break;
-
- case ERASE_CIRCLE:
- TdpEraseObject (info->drawport, info->circle);
- break;
-
- case DRAW_RECT:
- TdpDrawObject (info->drawport, info->rectangle);
- break;
-
- case ERASE_RECT:
- TdpEraseObject (info->drawport, info->rectangle);
- break;
- }
-
- return (int) INPUT_USED;
- }
-